import Vue from 'vue';
import VueRouter from 'vue-router';
// 登录
import loginRouter from './children/loginRouter';
import tabulationRouter from './children/tabulationRouter';
import itemManage from './children/itemManage';
import oneThingManage from './children/oneThingManage';
import oneThingCrossRule from './children/oneThingCrossRule';
import situation from './children/situation';
import examine from './children/examine';
import materials from './children/materials';

Vue.use(VueRouter);

const originalPush = VueRouter.prototype.push;

VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch((err) => err);
};
const routes = [
  // 重定向
  {
    path: '/',
    redirect: '/itemManage'
  },
  // 登录
  ...loginRouter,
  //列表制表页面
  ...tabulationRouter,
  ...examine,
  {
    path: '/layout', //最外层的根路由页面
    name: 'layout',
    component: () => import('@/views/layout/index'),
    children: [
      //子菜单
      ...itemManage,
      ...oneThingManage,
      ...oneThingCrossRule,
      ...situation,
      ...materials
    ]
  },
  {
    path: '/redirect/:path*', // 刷新路由
    component: () => import('@/views/redirect/index.vue')
  }
];

const router = new VueRouter({
  routes
});

export default router;
